import QtQuick
import QtQuick.Controls.Fusion

Slider {
    id: control
    signal clicked(double val)
    signal hoveredPos(bool hovered, double pos)
    height: 3
    to: 1
    handle: Item {}
    background: Rectangle {
        color: palette.midlight
        Rectangle {
            radius: 2
            color: palette.highlight
            height: parent.height
            width: control.position * parent.width
            Behavior on width {
                NumberAnimation {
                    duration: 150
                }
            }
        }
    }
    onMoved: {
        control.clicked(position);
    }

    MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.NoButton
        cursorShape: Qt.PointingHandCursor
        hoverEnabled: true
        onEntered: {
            if (!control.enabled) {
                return;
            }
            control.hoveredPos(true, mouseX / parent.width);
        }
        onExited: {
            if (!control.enabled) {
                return;
            }
            control.hoveredPos(false, mouseX / parent.width);
        }
    }
}
